package java基础知识;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * @author coderFu
 * @create 2022/3/4
 * 创建对象的五种方式
 */
public class CreateObjectFunction {

    public static void main(String[] args) throws IllegalAccessException, InstantiationException, InvocationTargetException, CloneNotSupportedException, ClassNotFoundException, NoSuchMethodException {


        /**
         * 直接new
         */
        CreateObjectFunction cof = new CreateObjectFunction();

        // 默认调用无参的构造方法
        Class.forName("java基础知识.CreateObjectFunction").newInstance();

        // 使用类直接创建对象
        CreateObjectFunction createObjectFunction = CreateObjectFunction.class.newInstance();

        // 使用反射的构造方法
        Constructor<CreateObjectFunction> constructor = CreateObjectFunction.class.getConstructor();
        CreateObjectFunction createObjectFunction1 = constructor.newInstance();

        // 通过克隆
        Object clone = cof.clone();

        // 使用反序列化实例化对象


    }
}
